package com.ciwong.epaper.modules.evaluate.ui.dialogfragment.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;


import java.util.ArrayList;
import java.util.List;

public abstract class BaseDFrgAdapter<E,T extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<T> {


    private final Context mContext;
    private final LayoutInflater from;
    private List<E> list = new ArrayList<>();
    public ICheckItemListener mListener;

    public void setCheckItemListener(ICheckItemListener listener) {
        mListener = listener;
    }

    public interface ICheckItemListener<T,E > {
        void  checkItem(T holder,E bean, int position);
    }


    public BaseDFrgAdapter(Context context) {
        this.mContext = context;
        from = LayoutInflater.from(mContext);
    }

    public void setData(List<E> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public T onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return getViewHolder(from, parent, viewType);
    }

    @Override
    public void onBindViewHolder(@NonNull T holder, int position) {
        onBind(holder, list, position);

    }

    @Override
    public int getItemCount() {
        return (list == null || list.size() <= 0) ? 0 : list.size();
    }

    public abstract T getViewHolder(LayoutInflater from, ViewGroup parent, int viewType);

    protected abstract void onBind(T holder, List<E> list, int position);
}
